/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Vector;
import javax.swing.text.StyledEditorKit.BoldAction;


/**
 *
 * @author RUOL
 */
public class Sinhvien {
    private String Masv;
    private String Hoten;
    private String Hinh;
    private String Gioitinh;
    private java.util.Date Ngaysinh;
    private String Diachi;
    private String Dienthoai;
    private String Email;
    private String Malop;
    private String Mota;

    /**
     * @return the masv
     */
    public String getMasv() {
        return Masv;
    }

    /**
     * @param masv the masv to set
     */
    public void setMasv(String masv) {
        this.Masv = masv;
    }

    /**
     * @return the hoten
     */
    public String getHoten() {
        return Hoten;
    }

    /**
     * @param hoten the hoten to set
     */
    public void setHoten(String hoten) {
        this.Hoten = hoten;
    }

    /**
     * @return the Hinh
     */
    public String getHinh() {
        return Hinh;
    }

    /**
     * @param Hinh the Hinh to set
     */
    public void setHinh(String Hinh) {
        this.Hinh = Hinh;
    }

    /**
     * @return the Gioitinh
     */
    public String getGioitinh() {
        return Gioitinh;
    }

    /**
     * @param Gioitinh the Gioitinh to set
     */
    public void setGioitinh(String Gioitinh) {
        this.Gioitinh = Gioitinh;
    }

    /**
     * @return the Ngaysinh
     */
    public java.util.Date getNgaysinh() {
        return Ngaysinh;
    }

    /**
     * @param Ngaysinh the Ngaysinh to set
     */
    public void setNgaysinh(java.util.Date Ngaysinh) {
        this.Ngaysinh = Ngaysinh;
    }

    /**
     * @return the Diachi
     */
    public String getDiachi() {
        return Diachi;
    }

    /**
     * @param Diachi the Diachi to set
     */
    public void setDiachi(String Diachi) {
        this.Diachi = Diachi;
    }

    /**
     * @return the Dienthoai
     */
    public String getDienthoai() {
        return Dienthoai;
    }

    /**
     * @param Dienthoai the Dienthoai to set
     */
    public void setDienthoai(String Dienthoai) {
        this.Dienthoai = Dienthoai;
    }

    /**
     * @return the Email
     */
    public String getEmail() {
        return Email;
    }

    /**
     * @param Email the Email to set
     */
    public void setEmail(String Email) {
        this.Email = Email;
    }

    /**
     * @return the Malop
     */
    public String getMalop() {
        return Malop;
    }

    /**
     * @param Malop the Malop to set
     */
    public void setMalop(String Malop) {
        this.Malop = Malop;
    }

    /**
     * @return the Mota
     */
    public String getMota() {
        return Mota;
    }

    /**
     * @param Mota the Mota to set
     */
    public void setMota(String Mota) {
        this.Mota = Mota;
    }
    //---------------------
    public Vector<Vector> DanhSachSV()
    {
        Vector<Vector> dssv = new Vector<Vector>();
        
        try
        {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select * from Sinhvien";
            Statement st=con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while(rs.next())
            {
                Vector<Object> dm = new Vector<Object>();
                dm.add(rs.getString("Masv"));
                dm.add(rs.getString("Hoten"));
                dm.add(rs.getString("Hinh"));
                dm.add(rs.getString("Gioitinh"));
                //dm.add(rs.getDate("Ngaysinh"));
               // dm.add(rs.getString("Diachi"));
                dm.add(rs.getString("Dienthoai"));
                //dm.add(rs.getString("Email"));
               
                //dm.add(rs.getString("Mota"));
                dssv.add(dm);
            }
        }
        catch(Exception ex)
        {
            dssv = null;
        }
        
        return dssv;
    }
    public Sinhvien TimtenSV()
    {
        Sinhvien dm1 = new Sinhvien();
        try
        {
            Connection con = ConnectToDatabase.getConnection();
           
            String query = "select * from Sinhvien where Hoten = '"+this.Hoten+"'";
            Statement st=con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while(rs.next())
            {
                dm1.setMasv(rs.getString("Masv"));
                dm1.setHoten(rs.getString("Hoten"));
                dm1.setHinh(rs.getString("Hinh"));
                dm1.setGioitinh(rs.getString("Gioitinh"));
                dm1.setNgaysinh(rs.getDate("Ngaysinh"));
                dm1.setDiachi(rs.getString("Diachi"));
                dm1.setDienthoai(rs.getString("Dienthoai"));
                dm1.setEmail(rs.getString("Email"));
                dm1.setMota(rs.getString("Mota"));
            }
        }
        catch(Exception ex)
        {
            dm1 = null;
        }
        
        return dm1;
    }
    public boolean XulyThemSinhVien()
    {
      boolean kq = true;
        
       try
        {
            Connection con = ConnectToDatabase.getConnection();
            String query = "insert into Sinhvien values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
            PreparedStatement ps = con.prepareStatement(query);
            ps.setString(1, this.Masv);
            ps.setString(2, this.Hoten);
            ps.setString(3, this.Hinh);
            ps.setString(4, this.Gioitinh);
            java.sql.Date ns = new Date(this.Ngaysinh.getTime());
            ps.setDate(5, ns);
            //ps.setString(5, this.Ngaysinh);
            ps.setString(6, this.Diachi);
            ps.setString(7, this.Dienthoai);
            ps.setString(8, this.Email);
            ps.setString(9, this.Malop);
            ps.setString(10, this.Mota);
            kq = ps.executeUpdate() > 0;
        }
        catch(Exception ex)
        {
            kq = false;
        }
        
        return kq;
    }
    public Sinhvien ThongTinSV()
    {
        Sinhvien dm = new Sinhvien();
        
        try
        {
            Connection con = ConnectToDatabase.getConnection();
             //select * from Sinhvien, Khoa_sinhvien,Tinhtranghocphi where Sinhvien.Masv='sv1'
            String query = "select * from Sinhvien where Masv = '"+this.Masv+"'";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while(rs.next())
            {
                dm.setMasv(rs.getString("Masv"));
                dm.setHoten(rs.getString("Hoten"));
                dm.setHinh(rs.getString("Hinh"));
                dm.setGioitinh(rs.getString("Gioitinh"));
                dm.setNgaysinh(rs.getDate("Ngaysinh"));
                dm.setDiachi(rs.getString("Diachi"));
                dm.setDienthoai(rs.getString("Dienthoai"));
                dm.setEmail(rs.getString("Email"));
                dm.setMota(rs.getString("Mota"));
            }
        }
        catch(Exception ex)
        {
            dm = null;
        }
        
        return dm;
    }
    public boolean CapNhatSV()
    {
        boolean kq = true;
        
        try
        {
            Connection con = ConnectToDatabase.getConnection();
            String query = "update Sinhvien set Masv='"+this.Masv+"', Hoten='"+this.Hoten+"', Gioitinh='"+this.Gioitinh+"', Diachi='"+this.Diachi+"', Dienthoai='"+this.Dienthoai+"', Email='"+this.Email+"', Malop='"+this.Malop+"', Mota='"+this.Mota+"' where Masv='"+this.Masv+"'";
            Statement st = con.createStatement();
            kq = st.executeUpdate(query) > 0;
        }
        catch(Exception ex)
        {
            kq = false;
        }
        
        return kq;
    }
     public boolean XoaSinhvien()
    {
        boolean kq = true;
        
        try
        {
            Connection con = ConnectToDatabase.getConnection();
            String query = "delete from Sinhvien where Masv='"+this.Masv+"'";
            Statement st = con.createStatement();
            kq = st.executeUpdate(query) > 0;
        }
        catch(Exception ex)
        {
            kq = false;
        }
        
        return kq;
    }
}
